package Set;

use Exporter 'import';
use Signature;
use TinyMessage;

@EXPORT = qw(shouldGet);

sub new {
	return bless {}, (shift);
}

sub put {
	my ($self, $obj) = @_;
	$self->{  signature($obj) } = $obj;	
}

sub exists {
	my ($self, $obj) = @_;
	return exists $self->{ signature($obj) };
}

sub values {
	return values(%{ (shift) });
}

sub value {
	my ($this, $obj) = @_;
	
	$sig = signature($obj);
	
	if (exists $this->{ $sig }) {
		return $this->{ $sig };
	}
	
	return undef;
}

sub empty {
	my ($this) = @_;
	return scalar( keys( %{ $this } ) ) == 0;
}

sub size {
	my ($this) = @_;
	return scalar( keys( %{ $this } ) );
}

sub keys {
	return  keys( %{ (shift) } );
}

sub shouldGet {
	my ($set, $sig) = @_;
	$sig = signature($sig);
	
	my $obj = $set->value($sig);
	
	if (!$obj) {
		fatal 'F_SIGNATURE_SET_GET', $sig, $set->keys();
	}
	
	return $obj;
}

1;